const gulp = require("gulp")
const cssmin = require("gulp-cssmin")
const uglify = require("gulp-uglify")
const autoprefixer = require("gulp-autoprefixer")
const babel = require("gulp-babel")
const sass = require("gulp-sass")(require("sass"))
const html = require("gulp-htmlmin")
const del = require("del")
const server = require("gulp-webserver")
function cssHandler(){
   return gulp
      .src("./src/css/*.css")
      .pipe(autoprefixer())
      .pipe(cssmin())
      .pipe(gulp.dest("./dist/css/"))
}
function jsHandler(){
   return gulp
   .src("./src/js/*.js")
   .pipe(babel({presets:["@babel/preset-env"]}))
   .pipe(uglify())
   .pipe(gulp.dest("./dist/js/"))
}
function scssHandler(){
   return gulp
   .src("./src/scss/*.scss")
   .pipe(sass())
   .pipe(cssmin())
   .pipe(gulp.dest("./dist/scss/"))
}
function htmlHandler(){
   return gulp
   .src("./src/html/*.html")
   .pipe(html({
      collapseWhitespace:true,
      collapseBooleanAttributes:true,
      removeAttributeQuotes:true,
      removeStyleLinkTypeAttributes:true,
      removeComments:true,
      removeEmptyAttributes:true,
      removeScriptTypeAttributes:true,
      minifyCSS:true,
      minifyJS:true
   }))
   .pipe(gulp.dest("./dist/html/"))
}
function imgHandler(){
   return gulp
   .src("./src/img/**.*")
   .pipe(gulp.dest("./dist/img/"))
}
function fontHandler(){
   return gulp
   .src("./src/font/**.*")
   .pipe(gulp.dest("./dist/font/"))
}
function untilsHandler(){
   return gulp
   .src("./src/node_modules/*")
   .pipe(gulp.dest("./dist/node_modules/"))
}
function delHandler(){
   return del(["./dist/"])
}
/* function serverHandler(){
   return gulp.src("./dist/")
   .pipe(server({
      host:"www.liuyongkang.com",
      port:9999,
      open:"./html/index.html",
      livereload:true
   }))
} */
/* function watchHandler(){
   gulp.watch("./src/html/*.html",htmlHandler)
   gulp.watch("./src/css/*.css",cssHandler)
   gulp.watch("./src/js/*.js",jsHandler)
   gulp.watch("./src/scss/*.scss",scssHandler)
} */
const _default = gulp.series(
   delHandler,
   gulp.parallel(cssHandler,jsHandler,scssHandler,htmlHandler,imgHandler,fontHandler,untilsHandler),
/*    serverHandler,
   watchHandler */
)
module.exports={
   cssHandler,
   jsHandler,
   scssHandler,
   htmlHandler,
   imgHandler,
   fontHandler,
   untilsHandler,
   default:_default
}